﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Task.BLL;
using Yipusoft.Task.Model;
using Yipusoft.Evaluate.BLL;
using Yipusoft.Evaluate.Model;
using System.Collections.Generic;

public partial class Evaluate_AwardNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, "320501"))
        {
            Response.Write("<script>alert('没有权限！');history.back(0);</script>");
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["AwardID"] == null)
            {
                ActionTitle.Text = "添加工作奖惩项目";
            }
            else
            {
                ActionTitle.Text = "编辑工作奖惩项目";
                BindData();
            }
        }
    }
    private void BindData()
    {
        AwardInfo award = Award.GetAward(int.Parse(Request.QueryString["AwardID"]));
        AwardName.Text = award.AwardName;
        AwardDate.Text = award.AwardDate.ToShortDateString();
        Description.Text = award.Description;
    }
    private void Insert()
    {
        AwardInfo award = new AwardInfo();
        award.AwardName = AwardName.Text;
        award.AwardDate = DateTime.Parse(AwardDate.Text);
        award.TotalScore = 0;
        award.Description = Description.Text;
        award.DepartmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 6) + "0";
        int AwardID = Award.Insert(award);

        EventLogInfo log = new EventLogInfo();
        log.EventTime = DateTime.Now;
        log.EventType = 1;
        log.EventData = "添加工作奖惩项目";
        log.ItemID = AwardID.ToString();
        log.ItemName = "Awards";
        log.ItemFullUrl = "AwardNew.aspx";
        log.CreatedBy = Context.User.Identity.Name;
        log.CreatedTime = DateTime.Now;
        log.UserIP = Request.UserHostAddress;
        EventLog.Insert(log);

        Prompt.Text = "提示：添加成功！";
    }
    private void Update()
    {
        AwardInfo award = Award.GetAward(int.Parse(Request.QueryString["AwardID"]));
        award.AwardName = AwardName.Text;
        award.AwardDate = DateTime.Parse(AwardDate.Text);
        award.TotalScore = 0;
        award.Description = Description.Text;
        Award.Update(award);

        EventLogInfo log = new EventLogInfo();
        log.EventTime = DateTime.Now;
        log.EventType = 1;
        log.EventData = "更新工作奖惩项目";
        log.ItemID = Request.QueryString["AwardID"];
        log.ItemName = "Awards";
        log.ItemFullUrl = "AwardNew.aspx";
        log.CreatedBy = Context.User.Identity.Name;
        log.CreatedTime = DateTime.Now;
        log.UserIP = Request.UserHostAddress;
        EventLog.Insert(log);

        Prompt.Text = "提示：更新成功！";
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["AwardID"] == null)
                Insert();
            else
                Update();
        }
        catch (Exception ex)
        {
            Prompt.Text = "错误：" + ex.Message;
        }
    }
}
